class Installr::Client::Runner

  def basic_usage
    "Usage: Installr [options] command [<args>] [command_options]\n" +
    "Try 'Installr help [command]' or 'Installr help options' for more information."
  end

  def display_usage
    if @usage
      puts @usage_error if @usage_error
      puts "Usage: #{@usage}"
      @exit_status = false
      return
    elsif @cmd_usage
      puts @cmd_usage
      return
    end
    puts command_usage
  end

  def command_usage
    <<-USAGE

#{basic_usage}

Currently available Installr commands are:

  Agent and Group Management
    create agent <agent_name> <agent_ip_address> --user <user_name> --password <user_password> [--remote-port <remote-port> --remote-upload-path <remote-upload-path>]
    create agent <agent_name> <agent_ip_address> --user <user_name> --auth-file <auth-file> [--passphrase <passphrase> --remote-port <remote-port> --remote-upload-path <remote-upload-path>]
    delete agent <agent_name>
    info agent <agent_name>
    list agents
    list agents from group <group_name>
    create group <group_name> <group_description>
    delete group <group_name>
    info group <group_name>
    list groups
    add agent <agent_name> to group <group_name>
    remove agent <agent_name> from group <group_name>

  Deployment
    deploy <app_name> <war_file> to group <group_name> [--remote-upload-path <remote-upload-path> --remote-port <remote-port>]
    undeploy <app_name> from group <group_name>
    deploy <app_name> <war_file> to agent <agent_name> [--remote-upload-path <remote-upload-path> --remote-port <remote-port>]
    undeploy <app_name> from agent <agent_name>
    activate <app_name> from group <group_name>
    activate <app_name> from agent <agent_name>
    deactivate <app_name> from group <group_name>
    deactivate <app_name> from agent <agent_name>
    start <app_name> from group <group_name>
    start <app_name> from agent <agent_name>
    stop <app_name> from group <group_name>
    stop <app_name> from agent <agent_name>
    list apps
    history <app_name> from local [--initialize]
    history <app_name> from group <group_name>
    history <app_name> from agent <agent_name>
    info head <app_name> from local
    info head <app_name> from agent <agent_name>
    info head <app_name> from group <group_name>
    set head <app_name> <app_md5hash> to group <group_name>
    set head <app_name> <app_md5hash> to agent <agent_name>

  Build and Find Dependencies
    make checkout --build-path <build_path> using <build_system> <target_rule>
    make build --build-path <build_path> [--no-depend] using <build_system> <target_rule>

  Scenario and Schedule
    create scenario <scenario_name> --scenario-file <scenario-file>
    delete scenario <scenario_name>
    list scenarios
    list scenarios from schedule <schedule_name>
    info scenario <scenario_name>
    execute scenario <scenario_name>
    add scenario <scenario_name> to schedule <schedule_name>
    remove scenario <scenario_name> from schedule <schedule_name>
    create schedule <schedule_name> --schedule <cron_format>
    delete schedule <schedule_name>
    list schedules
    info schedule <schedule_name>
    execute schedules
    activate schedule <schedule_name>
    deactivate schedule <schedule_name>

  Monitoring
    show status from group <group_name>
    show status from agent <agent_name>
    show log from agent <agent_name> [--application-server-log --remote-log-file <remote-log-file> --remote-log-length <remote-log-length>]
    show log from group <group_name> [--application-server-log --remote-log-file <remote-log-file> --remote-log-length <remote-log-length>]

  Bootstraping
    execute bootstrap group <group_name> --script-file <script_file> --local-upload-path <local-upload-path> --remote-upload-path <remote-upload-path>
    execute bootstrap agent <agent_name> --script-file <script_file> --local-upload-path <local-upload-path> --remote-upload-path <remote-upload-path>

  Database export/import
    export database from local --export-path <export-zip-file> [--initialize]
    import database to local --import-path <import-zip-file> [--initialize]

  Scenario subcommand
    WARNING: follwing commands are very dangerous because even a small mistake
    will destroy all your valuable file systems. So use them at your own risk.

    # is a comment sign
    exec <local_shell_command>
    ssh-agent <agent_name> <remote_shell_command>
    sftp-agent <agent_name> <source_file_full_path> <remote_file_full_path>
    ssh-group <group_name> <remote_shell_command>
    sftp-group <group_name> <source_file_full_path> <remote_file_full_path>
    Installr <Installr internal command>

  Help
    version
    help [command]
    help options
    options
USAGE

  end
end
